package com.zhhs.project.act.appactivity.common;



import com.zhhs.framework.web.domain.AjaxResult;
import org.springframework.util.Assert;

/**
 * @description: 断言
 * @author: xiaohu
 * @date: Created in 2021-11-11 12:25
 */
public class AssertUtil extends Assert {

    /**
     * 当为true时抛出异常
     */
    public static void trueAssert(boolean flag, String msg) {
        if (flag) {
            throw new BusinessException(msg);
        }
    }

    /**
     * 当为 false时抛出异常
     */
    public static void falseAssert(boolean flag, String msg) {
        trueAssert(!flag, msg);
    }


    /**
     * app端当为true时抛出错误异常返回json
     */
    public static void trueAssertErrorJson(boolean flag, String msg) {
        if (flag) {
            throw new AppJsonBusinessException(msg, AjaxResult.error(msg));
        }
    }
    /**
     * app端当为true时抛出警告异常返回json
     */
    public static void trueAssertWarnJson(boolean flag, String msg) {
        if (flag) {
            throw new AppJsonBusinessException(msg, AjaxResult.warn(msg));
        }
    }
    /**
     * app端当为true时抛出异常返回错误页面
     */
    public static void trueAssertPage(boolean flag, String msg) {
        if (flag) {
            throw new AppPageBusinessException(msg);
        }
    }
}
